#ifdef	TEXTURED
uniform sampler2D tex;
#endif
varying	vec3 vNormal;
varying	vec4 vPos;
varying	vec4 vPosMV;
varying	vec3 vPosM;

uniform float spotDecay = 0.5;
uniform float spotAng = 0.93;

void main()
{
	vec4	color = vec4(1.0,1.0,1.0,1.0);

#ifdef	VCOLOR
	color *= gl_Color;
#endif

#ifdef	TEXTURED
	color *= texture2D( tex, gl_TexCoord[0].st );
#endif

	float fact = clamp( (dot( normalize(vPosMV.xyz), vec3(0,0,-1) ) - spotAng) * spotDecay * 100.0, 0.0, 1.0 );
	//color *= fact;
	color.a = fact;
	//color.rgb *= fact;

#ifdef	MRT
	vec4 normal;
	normal.xyz = (vNormal * 0.5) + 0.5;
	
	vec4 pos;
//	pos.xyz = vPos.xyz / vPos.w;
//	pos.xy = (pos.xy * 0.5) + 0.5;
//	pos.xyz = vPosM.xyz / vPosM.w;
//	pos.xyz = (pos.xyz * 0.01) + 0.5;
	pos.xyz = vPosM;
	pos.xyz = (pos.xyz * 0.025) + 0.5;
	
	//to be used
	normal.w = 1.0;
	pos.w = 1.0;
	
	gl_FragData[0] = color;
	gl_FragData[1] = pos;
	gl_FragData[2] = normal;
#else
	gl_FragColor = color;
#endif
}
